﻿Imports MeoTom.Core

Namespace Control

    Partial Public Class CommentEdit
        Inherits UserControl

        Public cm As New BLL.Comments()
        Public util2 As New Utilities.Common()

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            Try
                If Not IsPostBack Then
                    Dim previousPage As String = ""
                    If Request.QueryString.ToString = vbNullString Then
                        previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO"))
                    Else
                        previousPage = Server.UrlEncode(Request.ServerVariables("PATH_INFO") & "?" & Request.QueryString.ToString())
                    End If
                    util2.ValidateLogin(previousPage)

                    cm.CommentsID = Integer.Parse(Request.QueryString("CommentsID"))
                    cm.GetByID()

                    txtBody.Value = cm.Body
                    txtEmail.Text = cm.AddedByEmail
                    txtName.Text = cm.AddedBy
                    txtURL.Text = cm.AddedByURL

                    UserEmail.InnerHtml = "Email (<a href=""mailto:" & cm.AddedByEmail & """ title=""send mail"">send e-mail</a>):"
                    divStatus.InnerHtml = WriteStatusComment(cm.Status, cm.AddedDate.ToString)
                End If
            Catch ex As Exception

            End Try
        End Sub

        Private Function WriteStatusComment(ByVal Status As Boolean, ByVal CreateDate As String) As String
            Dim strOut As New StringBuilder()
            Dim strCheck1 As String = " checked=""checked"""
            Dim strCheck2 As String = " checked=""checked"""

            If Not Status Then
                strCheck2 = ""
            Else
                strCheck1 = ""
            End If

            strOut.Append("<p><label><input type=""radio"" name=""cboStatus"" value=""0""").Append(strCheck1).Append(" />Approved</label></p>")
            strOut.Append("<p><label><input type=""radio"" name=""cboStatus"" value=""1""").Append(strCheck2).Append(" />Pending</label></p>")
            strOut.Append("<p><img src=""/Images/Calendar-scheduleHS.png"" width=""12"" height=""12"" alt=""Publish Date"" />&nbsp;Submitted on:").Append(CreateDate).Append("</p>")

            Return strOut.ToString()
        End Function

        Private Sub lnkDelete_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkDelete.Click
            Try
                cm.CommentsID = Integer.Parse(Request.QueryString("CommentsID"))
                cm.Delete()
                cm.WriteAricleComment(0)
            Catch ex As Exception

            End Try
            Response.Redirect("/mt-inside/ArticleComment.aspx")
        End Sub

        Private Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnUpdate.Click
            Try
                If Request.Form("cboStatus") = "1" Then
                    cm.Status = True
                Else
                    cm.Status = False
                End If
                cm.Body = txtBody.Value
                cm.AddedByEmail = txtEmail.Text
                cm.AddedBy = txtName.Text
                cm.AddedByURL = txtURL.Text
                cm.CommentsID = Integer.Parse(Request.QueryString("CommentsID"))
                cm.Update()
            Catch ex As Exception

            End Try
            Response.Redirect("/mt-inside/ArticleComment.aspx")
        End Sub
    End Class
End Namespace